import * as React from 'react';
import {observer} from 'mobx-react';
import {Table, Row, Col, Button, message} from 'antd';
import {PageBaseFormModal} from '../form/Form';
import {addStore,listStore,searchStore} from '../PageStore';

@observer
export class AddFormModal extends React.Component<any, any> {
    onOk(me){
        return function(e){
            if(addStore.isValid()){
                addStore.changeConfirmLoading(true);

                addStore.addPage(addStore.getValues())
                    .then((data)=>{
                        if(data.success){
                            message.success(data.message,3);
                            addStore.hide();
                            listStore.refresh(searchStore);
                        }else{
                            message.error(data.message,3);
                        }

                        addStore.changeConfirmLoading(false);
                    })
           }else{
               return false;
           }
        }
    }

    render() {
        return <PageBaseFormModal store={addStore} title="新增" onOk={this.onOk(this)}/>
    }
}
